package ${sourceBasePackage}.controller;

import com.cscec81.cloud.common.domain.CommonResp;
import com.riching.cloud.common.annotations.AnonymousAccess;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import ${sourceBasePackage}.dto.${entityName}Dto;
import ${sourceBasePackage}.dto.${entityName}ReqDto;
import ${sourceBasePackage}.domain.${entityName};
import ${sourceBasePackage}.service.${entityName}Service;

import java.util.List;

/**
 * ${description}(${entityName})控制类
 * @author ${author}
 */
@RestController
@Api(value = "${entityName}Controller", tags = "${description}")
@RequestMapping(value = "/${entityName?uncap_first}")
public class ${entityName}Controller {

	@Autowired
	private ${entityName}Service service;

    /**
     * ${description}分页查询
     * @param ${entityName?uncap_first}ReqDto
     * @return
     */
    @PostMapping(path = "queryPage")
    @ApiOperation("${description}分页查询")
    @AnonymousAccess
	public CommonResp<Page<${entityName}Dto>> queryPage(@RequestBody ${entityName}ReqDto ${entityName?uncap_first}ReqDto) {
        Page<${entityName}Dto> page = service.queryPage(${entityName?uncap_first}ReqDto);
		return CommonResp.success(page);
	}

    /**
     * ${description}条件查询
     * @param ${entityName?uncap_first}ReqDto
     * @return
     */
    @PostMapping(path = "queryList")
    @ApiOperation("${description}条件查询")
    @AnonymousAccess
    public CommonResp<List<${entityName}Dto>> queryList(@RequestBody ${entityName}ReqDto ${entityName?uncap_first}ReqDto) {
        List<${entityName}Dto> list = service.queryList(${entityName?uncap_first}ReqDto);
        return CommonResp.success(list);
    }

    /**
    * 通过id查询
    * @param ${pkPropertyName}
    * @return
    */
    @ApiOperation(value="通过id查询")
    @PostMapping("/getById")
    @AnonymousAccess
    public CommonResp<${entityName}Dto> getById(@RequestParam("${pkPropertyName}") ${pkPropertyType} ${pkPropertyName}) {
        ${entityName}Dto ${entityName?uncap_first}Dto = service.getById(${pkPropertyName});
        return CommonResp.success(${entityName?uncap_first}Dto);
    }

    /**
     * ${description}新增
     * @param ${entityName?uncap_first}Dto
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("${description}新增")
    @AnonymousAccess
    public CommonResp add(@RequestBody ${entityName}Dto ${entityName?uncap_first}Dto) {
        try {
            service.add(${entityName?uncap_first}Dto);
            return CommonResp.success();
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResp.fail(e.getMessage());
        }
    }

    /**
     * ${description}修改
     * @param ${entityName?uncap_first}Dto
     * @return
     */
    @PostMapping("/update")
    @ApiOperation("${description}修改")
    @AnonymousAccess
    public CommonResp update(@RequestBody ${entityName}Dto ${entityName?uncap_first}Dto) {
        try {
            service.update(${entityName?uncap_first}Dto);
            return CommonResp.success();
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResp.fail(e.getMessage());
        }
    }

    /**
     * ${description}删除
     * @param ${pkPropertyName}
     * @return
     */
    @GetMapping("/delete")
    @ApiOperation("${description}删除")
    @AnonymousAccess
    public CommonResp delete(@RequestParam("${pkPropertyName}") ${pkPropertyType} ${pkPropertyName}) {
        try {
            service.delete(${pkPropertyName});
            return CommonResp.success();
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResp.fail(e.getMessage());
        }
    }

}
